package com.otoe.dilidilivid.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.otoe.dilidilivid.view.activity.CollectionVideoActivity;
import com.otoe.dilidilivid.data.entity.FavoritesInfo;
import com.otoe.dilidilivid.R;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class FavoriteAdapter extends RecyclerView.Adapter<FavoriteAdapter.VH> {

    private List<FavoritesInfo> mDatas;
    public FavoriteAdapter(List<FavoritesInfo> datas){
        this.mDatas = datas;
    }
    public static class VH extends RecyclerView.ViewHolder{
        public TextView name;
        public TextView size;
        public ImageView show;
        public Context context;
        public VH(View v){
            super(v);
            name=(TextView) v.findViewById(R.id.fv_name);
            size=(TextView) v.findViewById(R.id.fv_num);
            show=(ImageView) v.findViewById(R.id.fv_show);
            context = v.getContext();
        }
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        holder.name.setText(mDatas.get(position).getName());
        holder.size.setText(mDatas.get(position).getSize()+"");
        holder.show.setImageResource(mDatas.get(position).getShow());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //item点击事件
                Intent intent = null;
                intent = new Intent(holder.context, CollectionVideoActivity.class);
                holder.context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }


    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = View.inflate(parent.getContext(), R.layout.favorite_list_item, null);
        return new VH(v);
    }

}
